<?php

namespace Xrfg\Core\Trading\SystemAccount\Observers;

use Xrfg\Core\Common\Services\Proof;
use Xrfg\Core\Trading\SystemAccount\Models\SystemAccount;
use Xrfg\Core\Trading\SystemAccount\Models\SystemAccountCapitalflow;

class AccountObserver
{
    public function updated(SystemAccount $account)
    {
        $log = new SystemAccountCapitalflow();
        $log->system_account_id = $account->id;
        $log->before = $account->getOriginal('number');
        $log->number = $account->numberChange ?: 0;
        $log->after = $account->number;
        $log->certificate = Proof::encode($account->proofId[0], $account->proofId[1], $account->proofId[2]);
        $log->proof_id = $account->proofId[0];
        $log->class_id = $account->proofId[1];
        $log->op_id = $account->proofId[2];
        $log->version = $account->version;
        $log->save();
    }
}
